<?php
namespace Library;
use Library\Interceptor;
use Library\Route;
use Library\Common;

class Request
{
	protected $_SERVER;
	
	protected $_POST;
	
	protected $_GET;
	
	protected $_REQUEST;
	
	protected $isInterceptor;
	
	public function __construct($_SERVERS,$_POSTS,$_GETS,$_REQUESTS){
		$this->_SERVER = $_SERVERS;
		$this->_POST = $_POSTS;
		$this->_GET = $_GETS;
		$this->_REQUEST = $_REQUESTS;
		//	验证拦截器
		$this->isInterceptor = Config::get("app","isInterceptor");
		
		if ( $this->isInterceptor ){
			//	注册拦截器
			$this->regInterceptor();
		}else{
			//	直接进入路由
			$this->endRoute();
		}
	}
	//	进入路由
	public function endRoute(){
		//	路径补全
		$this->_SERVER["PATH_INFO"] = Common::completePath($this->_SERVER["PATH_INFO"]);
		new Route($this->_SERVER["PATH_INFO"]);
	}
	
	
	//	拦截器
	public function regInterceptor(){
		new Interceptor($this->_SERVER,$this->_POST,$this->_GET,$this->_REQUEST);
	}
	
	//	获取请求头
	public function getServer(){
		var_dump($this->_SERVER);
		return $this->_SERVER;
	}
	
	//	获取请头体
	public function getRequest(){
		return $this->_REQUEST;
	}
	
	//	获取POST请求数据
	public function getPost(){
		return $this->_POST;
	}
	
	//	获取GET请求数据
	public function getGet(){
		return $this->_GET;
	}
}
?>